/**
 * Browser detection
 * @class _jsc.client
 */

_jsc.client = (function() {
	var t = {
		/**
		 * Internet Explorer version number or 0.  Example: 6
         * @property ie
         * @type float
         */
		ie:0,
		
		/**
         * Opera version number or 0.  Example: 9.2
         * @property opera
         * @type float
         */
		opera:0,
		
		/**
		 * Gecko engine revision number.  Will evaluate to 1 if Gecko 
         * is detected but the revision could not be found. Other browsers
         * will be 0.  Example: 1.8
         * <pre>
         * Firefox 1.0.0.4: 1.7.8   <-- Reports 1.7
         * Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
         * Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
         * Firefox 3 alpha: 1.9a4   <-- Reports 1.9
         * </pre>
         * @property gecko
         * @type float
         */
		gecko:0,
		
		/**
         * AppleWebKit version.  KHTML browsers that are not WebKit browsers 
         * will evaluate to 1, other browsers 0.  Example: 418.9.1
         * <pre>
         * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the 
         *                                   latest available for Mac OSX 10.3.
         * Safari 2.0.2:         416     <-- hasOwnProperty introduced
         * Safari 2.0.4:         418     <-- preventDefault fixed
         * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
         *                                   different versions of webkit
         * Safari 2.0.4 (419.3): 419     <-- Current Safari release
         * Webkit 212 nightly:   522+    <-- Safari 3.0 (with native SVG) should
         *                                   be higher than this
         *                                   
         * </pre>
         * http://developer.apple.com/internet/safari/uamatrix.html
         * @property webkit
         * @type float
         */
		webkit:0,
		
		/**
		 * Firefox version number. Example: 2
		 * @property firefox
		 * @type float 
		 */
		firefox:0
	};
	
	var ua = navigator.userAgent.toLowerCase();
	
	// Modern KHTML browsers should qualify as Safari X-Grade
	if ((/KHTML/i).test(ua)) {
		t.webkit = 1;
    }
	// Modern WebKit browsers are at least X-Grade
    m = ua.match(/AppleWebKit\/([^\s]*)/i);
    if (m&&m[1]) {
        t.webkit = parseFloat(m[1]);
    }
	
	if (!t.webkit) { // not webkit
        // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
        m = ua.match(/Opera[\s\/]([^\s]*)/i);
        if (m&&m[1]) {
            t.opera = parseFloat(m[1]);
        } else { // not opera or webkit
            m = ua.match(/MSIE\s([^;]*)/i);
            if (m&&m[1]) {
                t.ie=parseFloat(m[1]);
            } else { // not opera, webkit, or ie
                m = ua.match(/Gecko\/([^\s]*)/i);
                if (m) {
                    t.gecko = 1; // Gecko detected, look for revision
                    m = ua.match(/rv:([^\s\)]*)/i);
                    if (m&&m[1]) {
                        t.gecko = parseFloat(m[1]);
                    }
					m = ua.match(/firefox\/([^\s\)]*)/i);
					if (m&&m[1]) {
						t.firefox = parseFloat(m[1]);
					};
                }
            }
        }
    }
	
	// quick invoke support
	t.isSafari = (t.webkit > 1);
	t.isOpera = (ua.indexOf('opera') > -1);
	t.isIE = (!t.isOpera && ua.indexOf('msie') > -1);
	t.isFF = (!t.isOpera &&!ua.isIE&&ua.indexOf('firefox') > -1);
	return t;
})();